﻿

//分页对象并 绘制
function Paging() {
    this.config =
       {
           DivId: "mypaging",
           DivStyle: "",
           MaxNumber: 0
       }

    this.property = {
        indexNumber: 1,
        startNumber: 1,
        endNumber: 10,
    }



    this.event = {
        reDrawAfterParam:"",
        reDrawBeforeParam: "",
        onclickBeforParam: "",
        onclickAfterParam: "",
        onclickAfter: function (param) { },
        onclickBefor: function (param) { },
        reDrawAfter: function (param) { },
        reDrawBefore: function (param) { }
    }
    paging_event(this);
    //动作
    if (typeof (Paging.initailed) == "undefined") {
        Paging.prototype.reDraw = function () {
           // this.event.reDrawBefore(this.event.reDrawBefore);
            var htm = '<span  class="BackPage"> <a href="#" style="">&lt;上一页</a></span>\
                <span class="PageNumber"><a class="on " href="#">1</a>\
                <a class="" href="#">10</a></span>\
                <span class="NextPage"><a href="#" >下一页&gt;</a></span>';
            //分页对象
            var pagingObj = $("#" + this.config.DivId)
            //初步绘制出
            pagingObj.html("").html(htm);
            //上一页  页码  下一页 obj
            var pagingBackPage = pagingObj.find(".BackPage");
            var pagingNextPaga = pagingObj.find(".NextPage");
            var pagingNumber = pagingObj.find(".PageNumber");
            //对上一页下一页的绘制
            if (this.config.MaxNumber == this.property.indexNumber) {
                pagingNextPaga.hide();
            }
            if (this.property.indexNumber == 1) {
                pagingBackPage.hide();
            }
         334473
            //对数码的绘制
            pagingNumber.html("");
            for (var i = this.property.startNumber; i <= this.property.endNumber; i++) {
                if (i > this.config.MaxNumber) {
                    continue;
                }
                var htm_code = '<a class="" href="#">' + i + '</a>';
                if (i == this.property.indexNumber) {
                    htm_code = '<a class="on" href="#">' + i + '</a>';
                }
                pagingNumber.append(htm_code);
            }
            this.event.reDrawAfter(this.event.reDrawAfter);
        }
  
    }
    Paging.initailed = true;
}

function HomeIndex_Paging_Action()
{
    var page = new Paging();
    page.property = {
        indexNumber: 1,
        startNumber: 1,
        endNumber: 10
    }
    page.config =
                   {
                       DivId: "mypaging",
                       DivStyle: "",
                       MaxNumber: 10
                   }
    var PageStartTime =new Date().getTime();
    var param = {
        "TableName":
           {
               "TableName": "DMP_Bolg_Shuoshuo",
               "DataTime": PageStartTime,
               "IndexDelIds": [],
               "IsRTData": true,
               "sortName": "Time",
               "sortType": "desc",
               "Filter": {},
               "pagingCount": page.property.endNumber - page.property.startNumber+1,
               "pagingNumber": page.property.indexNumber
           }
    }
    page.event.reDrawBeforeParam = param;
    page.event.reDrawBefore = function (param)
    {
        $.post("/JsonDate/getmyTableByTableInfo", param, function (mytable, status) {
            if (status == "success") {
                page.config.MaxNumber = mytable.TableResult_Count;
                page.event.reDrawAfterParam = mytable;
                page.event.reDrawAfter = function (mytable) {
                    var ssList = mytable.TableResult_DbList;
                    var maxPage = mytable.TableResult_Count / 10;
                    mytable.TableResult_Count % 10 > 0 ? maxPage++ : "";
                    //页面数据绘制
                    $(".bg_page_top_content_itemList").html("");
                    for (var i in ssList) {
                        item = ssList[i];
                        var ssContent = '<div class="bg_page_top_content_item">\
                            <div class="bg_page_top_content_item">\
                            <div style="width: 100%; height: 15px;"></div>\
                            <div class="bg_page_top_content_item_info" style="text-align: left;\
                            margin: 0 auto; width: 95%; min-height: 50px; max-height: 500px; ">' + item.MessageProfile;

                        ssContent += '<div style="margin-right: 5%; text-align: right;">\
                                <span style="   color: crimson;margin-right: 69%;">浏览' + item.PageViewNumber + '次</span>\
                                <span style="margin: 5px;">点赞(' + item.PointNumber + ')</span>\
                                <span style="margin: 5px;">分享(' + item.shareNumber + ')</span>\
                            </div>\
                        </div>\
                        <div style="width: 100%; height: 15px;"></div>\
                    </div>';
                        $(".bg_page_top_content_itemList").append(ssContent);
                    }
                }
                page.reDraw();
            }
        });
    }
   








}
function paging_event(page) {
    $("#" + page.config.DivId).click(function (e) {
        //page.event.onclickBeforParam(page.event.onclickBeforParam);
        var e = e || window.event,
            target = e.target || e.srcElement;
        //输出点击div的id   
        var indexObj = $(target); //当前点击对象
        //过滤
        if (indexObj[0].tagName != "A")
        { return false; }
        if (parseInt(indexObj.html()) == page.property.indexNumber) { return false;}
        var indexOn = $(this).find(".on");
        if (indexObj.html() == "&lt;上一页") {
            page.property.indexNumber--;
        }

        else if (indexObj.html() == "下一页&gt;") {
            page.property.indexNumber++;
        }
        else {
            page.property.indexNumber = parseInt(indexObj.html());
        }

        var NumberCount = (page.property.endNumber + 1 - page.property.startNumber);
        var Numberdown = page.property.startNumber + 3;
        var NumberUp = page.property.endNumber - 3;


        if (Numberdown > page.property.indexNumber) {
            page.property.startNumber = page.property.startNumber - (Numberdown - page.property.indexNumber);
            page.property.endNumber = page.property.endNumber - (Numberdown - page.property.indexNumber);
            if (page.property.startNumber < 1) {
                page.property.startNumber = 1;
                page.property.endNumber = NumberCount;
            }
        }
        if (page.property.indexNumber > NumberUp) {
            page.property.startNumber = page.property.startNumber + (page.property.indexNumber - NumberUp);
            page.property.endNumber = page.property.endNumber + (page.property.indexNumber - NumberUp);
            if (page.property.endNumber > page.config.MaxNumber) {
                page.property.startNumber = page.config.MaxNumber - NumberCount + 1;
                page.property.endNumber = page.config.MaxNumber;
            }
        }

       // page.event.onclickAfter(page.event.onclickAfterParam);
        page.reDraw();
    })
}


 

